import plugin from '../../../lib/plugins/plugin.js'
import { segment } from "oicq"
import path from "path"
// import {get_help_img} from "./showData.js"
import puppeteer from "../../../lib/puppeteer/puppeteer.js";
import Help from "../model/help.js";
import md5 from "md5";
//import data from '../model/XiuxianData.js'
//插件根目录
const __dirname = path.resolve() + path.sep + "plugins" + path.sep + "xiuxian-emulator-plugin";
//帮助图片
const help_path = path.join(__dirname, "/resources/help/help/xiuxian_help.png")

let helpData = {
    md5: "",
    img: "",
};
export class xiuxian_help extends plugin {
    constructor() {
        super({
            /** 功能名称 */
            name: '修仙帮助',
            /** 功能描述 */
            dsc: '修仙模块',
            event: 'message',
            /** 优先级，数字越小等级越高 */
            priority: 600,
            rule: [
                {
                    reg: '^#修仙帮助$',
                    fnc: 'help'
                },

            ]
        })
    }

    // //修仙帮助
    // async xiuxian_help(e) {
    //     let help_img = await get_help_img(e);
    //     e.reply(help_img);
    //     return;
    // }

    /**
     * rule - 修仙帮助
     * @returns
     */
    async help(e) {
        let data = await Help.get(e);
        if (!data) return;
        let img = await this.cache(data);
        await e.reply(img);
    }

    async cache(data) {
        let tmp = md5(JSON.stringify(data));
        if (helpData.md5 == tmp) return helpData.img;

        helpData.img = await puppeteer.screenshot("help", data);
        helpData.md5 = tmp;
        return helpData.img;
    }

}